﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace OZDoo.WebCommon.Message
{
    public class ShowMessage
    {
        /// <summary>
        /// 弹出消息内容
        /// </summary>
        /// <param name="strMsg">消息内容</param>
        public static void ShowAlert(string strMsg)
        {
            System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>window.alert('" + strMsg + "');</script>");
        } /// <summary>
        /// 弹出消息内容（最好用这个，不会破坏页面样式）
        /// </summary>
        /// <param name="strMsg">消息内容</param>
        public static void ShowAlert(System.Web.UI.Page page, string strMsg)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", "alert('" + strMsg + "')", true);
        }
        /// <summary>
        /// 弹出消息
        /// </summary>
        /// <param name="strMsg">消息内容</param>
        /// <param name="isEnd">是否终止当前程序运行</param>
        public static void ShowAlertStopApp(System.Web.UI.Page page,string strMsg, bool isEnd)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", "alert('" + strMsg + "')", true);
            //System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>window.alert('" + strMsg + "');</script>");
            if (isEnd)
                return;
        }
        /// <summary>
        /// 弹出消息，并返回上一页
        /// </summary>
        /// <param name="strMsg">消息内容</param>
        public static void ShowAlertAndBack(string strMsg)
        {
            System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>window.alert('" + strMsg + "');window.history.back();</script>");
        }
        /// <summary>
        /// 弹出消息并刷新当前页面和父页面
        /// </summary>
        /// <param name="page">当前页面的实例</param>
        /// <param name="strMsg">消息内容</param>
        public static void ShowAlertAndFlushChildParentFrom(System.Web.UI.Page page, string strMsg)
        {
            page.Response.Write("<Script Language='JavaScript'>window.alert('" + strMsg + "');window.location.href='" + page.Request.Url + "';parent.location.href=parent.location.href;</script>");
        }

        /// <summary>
        /// 弹出消息并刷新当前页面
        /// </summary>
        /// <param name="page">当前页面的实例</param>
        /// <param name="strMsg">消息内容</param>
        public static void ShowAlertAndFlushChildFrom(System.Web.UI.Page page, string strMsg)
        {
            page.Response.Write("<Script Language='JavaScript'>window.alert('" + strMsg + "');window.location.href='" + page.Request.Url + "';</script>");
        }
        /// <summary>
        /// 弹出消息跳转到指定的页面
        /// </summary>
        /// <param name="strMsg">消息内容</param>
        /// <param name="Url">要跳转的地址</param>
        public static void ShowAlertAndGo(string strMsg, string Url)
        {
            System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>window.alert('" + strMsg + "');window.location.href ='" + Url + "'</script>");
        }
        /// <summary>
        /// 弹出带有确定/取消按钮的对话框（confirm）
        /// </summary>
        /// <param name="strMsg">消息内容</param>
        /// <param name="strUrl_Yes">点击确定要跳转的地址</param>
        /// <param name="strUrl_No">点击取消要跳转的地址</param>
        public static void ShowConfirm(string strMsg, string strUrl_Yes, string strUrl_No)
        {
            System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>if ( window.confirm('" + strMsg + "')) {  window.location.href='" + strUrl_Yes +
                              "' } else {window.location.href='" + strUrl_No + "' };</script>");
        }
        /// <summary>
        /// 弹出带有确定/取消按钮的对话框（confirm）
        /// </summary>
        /// <param name="strMsg">消息内容</param>
        /// <param name="strUrl_Yes">点击确定要跳转的地址</param>
        /// <param name="strUrl_No">点击取消要跳转的地址</param>
        public static void ShowConfirm(string strMsg)
        {
            System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'> window.confirm('" + strMsg + "');</script>");
        }
        /// <summary>
        /// 刷新当前页面和父页面
        /// </summary>
        /// <param name="strMsg"></param>
        public static void FlushCurrenParentFrom(System.Web.UI.Page page)
        {
            System.Web.HttpContext.Current.Response.Write("<script>window.location.href='" + page.Request.Url + "';parent.location.href=parent.location.href;</script>");
        }
        /// <summary>
        /// 刷新当前页面
        /// </summary>
        /// <param name="strMsg"></param>
        public static void FlushCurentFrom(System.Web.UI.Page page)
        {
            System.Web.HttpContext.Current.Response.Write("<script>window.location.href='" + page.Request.Url + "';</script>");
        }
        /// <summary>
        /// 调用js方法
        /// </summary>
        /// <param name="page">当前页面对象（Page）</param>
        /// <param name="functionName">js方法名称</param>
        /// <param name="paramter">js参数</param>
        public static void ExecClientScript(System.Web.UI.Page page, string functionName, string paramter)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", functionName + "('" + paramter + "')", true);
        }
        /// <summary>
        /// 调用js方法
        /// </summary>
        /// <param name="page">当前页面对象（Page）</param>
        /// <param name="functionName">js方法名称</param>
        /// <param name="paramter1">js参数</param>
        /// <param name="paramter2">js参数</param>
        public static void ExecClientScript(System.Web.UI.Page page, string functionName, string paramter1, string paramter2)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", functionName + "('" + paramter1 + "','" + paramter2 + "')", true);
        }
        /// <summary>
        /// 调用js方法
        /// </summary>
        /// <param name="page">当前页面对象（Page）</param>
        /// <param name="functionName">js方法名称</param>
        public static void ExecClientScript(System.Web.UI.Page page, string functionName)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", functionName + "()", true);
        }
    }
}
